package hotLeetcode;

import java.util.ArrayList;
import java.util.List;

public class H22Leetcode {
    public List<String> generateParenthesis(int n) {
        List<String> res = new ArrayList<>();
        backTrack(res, "", 0, 0, n);
        return res;




    }

    private void backTrack(List<String> res, String current, int left , int right, int max) {
        if (current.length() == max * 2) {
            res.add(current);
            return;
        }
        if (left < max) {
            backTrack(res, current + "(", left + 1, right, max);
        }

        if (right < left) {
            backTrack(res, current + ")", left, right + 1, max);
        }

    }
}
